<?php

/*
 * 作者:liuleyi
 * 功能描述:原材料类型控制器
 * 修改记录
 * 修改时间   修改人     修改描述
 */

namespace Admin\Controller;

use Think\Controller;

class MaterialTypeController extends Controller {

    public function add() {

        if (!empty($_POST)) {
            $MaterialTypeID = get_guid(__FUNCTION__);
            $func = new \Admin\Func\Func904020101($MaterialTypeID, I('MaterialTypeName'), I('MaterialTypeDesc'));

            if ($func->execute() === false) {
                $this->error("新增失败:" . $func->getErrMsg());
            } else {
                // $this->display();
                $this->success('新增成功！');
            }
            //  $this->display();
        } else {
            $location = new \Admin\Func\Func999010102('904020101');
            $location->execute();
            $this->assign('loction', $location->getRst());
            $this->display();
        }
    }

    public function del($MaterialTypeID) {
        $func = new \Admin\Func\Func904020103(I('MaterialTypeID'));
        if ($func->execute() === false) {
            $this->error('删除失败' . $func->getErrMsg());
        } else {
            $this->redirect('MaterialType/lst');
        }
    }

    public function edit($MaterialTypeID) {

        if (!empty($_POST)) {
            $func = new \Admin\Func\Func904020102(I('MaterialTypeID'), I('MaterialTypeName'), I('MaterialTypeDesc'));
            if ($func->execute() === false) {
                $this->error("编辑失败:" . $func->getErrMsg());
            } else {
                $this->success('编辑成功！');
            }
        } else {

            $func = new \Admin\Func\Func904020104($MaterialTypeID);
            if ($func->execute() === false) {
                $this->error('查询失败:' . $func->getErrMsg());
            } else {
                $this->assign('post', $func->getRst()[0]);
                $location = new \Admin\Func\Func999010102('904020102');
                $location->execute();
                $this->assign('loction', $location->getRst());
                $this->display();
            }
        }
    }

    public function lst() {


        $func = new \Admin\Func\Func904020105(I('MaterialTypeName'));
        if ($func->execute() === false) {
            $this->error('查询失败:' . $func->getErrMsg());
        } else {

            $this->assign('lst', $func->getRst());
        }
        $location = new \Admin\Func\Func999010102('904020105');
        $location->execute();
        $this->assign('loction', $location->getRst());
        $this->display();
    }

}
